<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet"
	href="<c:url value='/static/themes/lightbox2-master/css/lightbox.min.css'/>" />
<script src="<c:url value='/static/jquery/jquery-1.9.1.min.js'/>"
	type="text/javascript"></script>
<script type="text/javascript"
	src="<c:url value='/static/themes/js/jquery.datatables.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/static/datetimepicker/js/bootstrap-datetimepicker.js'/>"charset="UTF-8"></script>

<title>买手账户管理</title>
</head>
<body>
	<div class="panel panel-default bk-bg-white">
		<div class="panel-body">
			<form class="form-horizontal" id="searchForm" method="post"
				action="#">
				<div class="row">
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">生财ID:</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="buyersUserID"
								id="buyersUserID" placeholder="生财ID">
						</div>
					</div>

					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">买手登陆账号:</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="userName"
								id="userName" placeholder="买手登陆账号">
						</div>
					</div>
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">账号状态:</label>
						<div class="col-sm-8">
							<select id="accountStatus" name="accountStatus"
								class="form-control">
								<option value="">所有状态</option>
								<option value="0">使用中</option>
								<option value="1">已冻结</option>
							</select>
						</div>
					</div>
				</div>
				<div class="row">

					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">联系电话:</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="phone" id="phone"
								placeholder="联系电话">
						</div>
					</div>
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">联系QQ:</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="qqNo" id="qqNo"
								placeholder="联系QQ">
						</div>
					</div>
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">联系微信:</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="" wecharNo
								id="wechatNo" placeholder="联系微信">
						</div>
					</div>
				</div>
				<div class="row">
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">买手姓名:</label>
						<div class="col-sm-8">
							<input type="text" class="form-control" name="fullName"
								id="fullName" placeholder="买手姓名">
						</div>
					</div>
					<div class="form-group col-sm-4">
						<label class="col-sm-4 control-label">注册时间:</label>
						<div class="col-sm-8">
							<input class="input-append date form_datetime form-control"
								name="startRegistrationTime" id="startRegistrationTime">
							<span class="add-on"><i class="icon-remove"></i></span> <span
								class="add-on"><i class="icon-calendar"></i></span>
						</div>
					</div>
					<div class="form-group col-sm-4">
						<label class="col-sm-1 control-label">-</label>
						<div class="col-sm-8">
							<input class="input-append date form_datetime form-control"
								name="endRegistrationTime" id="endRegistrationTime"> <span
								class="add-on"><i class="icon-remove"></i></span> <span
								class="add-on"><i class="icon-calendar"></i></span>
						</div>
					</div>
				</div>
				<div class="form-group col-sm-12"
					style="padding-bottom: 15px; text-align: center;">
					<button id="search" type="button"
						class="btn btn-primary glyphicon glyphicon-search">搜索</button>
					<button id="report" type="button"
						class="btn btn-success glyphicon glyphicon-download">
						批量导出</button>
				</div>
			</form>
		</div>
	</div>
	<!-- panel-body -->
	<div id="message"></div>
	<!-- panel -->
	<div class="panel panel-default">
		<div class="panel-body">
			<div class="table-responsive">
				<div id="table1_wrapper" class="dataTables_wrapper no-footer">
					<table id="table" class="display nowrap" cellspacing="0"
						width="100%">
						<thead>
							<tr role="row">
								<th>生财ID</th>
								<th>登陆账号</th>
								<th>注册时间</th>
								<th>联系电话</th>
								<th>QQ</th>
								<th>微信</th>
								<th>买手姓名</th>
								<th>账号状态</th>
								<th></th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
		<div id="page"></div>
	</div>

	<script type="text/javascript">
		$(function($) {
			//日期控件
			$('#startRegistrationTime').datetimepicker({
				language : 'zh-CN',
				format : 'yyyy-mm-dd hh:ii', 
				autoclose : true,
				todayBtn : true,
				minuteStep : 10
			}).on('changeDate', function (ev) {
				var starttime = $(this).val();
				$('#endRegistrationTime').datetimepicker('setStartDate',starttime);
	            $(this).datetimepicker('hide');  
	        });
			
			$('#endRegistrationTime').datetimepicker({
				language : 'zh-CN',
				format : 'yyyy-mm-dd hh:ii',
				autoclose : true,
				todayBtn : true,
				minuteStep : 10
			}).on('changeDate', function (ev) {
				var time = $(this).val();
				$('#startRegistrationTime').datetimepicker('setEndDate',time);
	            $(this).datetimepicker('hide');  
	        });

			function doSearch(refresh) {
				var table = $('#table')
						.DataTable(
								{
									"processing" : true,
									"serverSide" : true,
									"bLengthChange" : false,
									"bFilter" : false,
									"bSort" : false,
									"bDestroy" : true,
									"sScrollX" : "100%",
									"sScrollY" : "100%",
									"language" : {
										"url" : path
												+ "/static/language_datatables.json"
									},
									"ajax" : {
										"url" : path
												+ "/user/getBuyersUsersList",
										"type" : "POST",
										"data" : {
											"buyersUserID" : $('#buyersUserID')
													.val(),
											"userName" : $('#userName').val(),
											"accountStatus" : $(
													'#accountStatus').val(),//账号状态
											"phone" : $('#phone').val(),//联系电话
											"qqNo" : $('#qqNo').val(),//联系QQ
											"wechatNo" : $('#wechatNo').val(),//联系微信
											"fullName" : $('#fullName').val(),
											"startRegistrationTime" : $(
													'#startRegistrationTime')
													.val(),
											"endRegistrationTime" : $(
													'#endRegistrationTime')
													.val()
										}
									},
									"oSearch" : {

									},
									"columns" : [ {
										"data" : "buyersUserId",
										"width" : "10%"
									}, {
										"data" : "userName",
										"width" : "10%"
									}, {
										"data" : "registrationTime",
										"width" : "15%"
									}, {
										"data" : "phone",
										"width" : "10%"
									}, {
										"data" : "qqno",
										"width" : "10%"
									}, {
										"data" : "wechatNo",
										"width" : "10%"
									}, {
										"data" : "fullName",
										"width" : "10%"
									}, {
										"data" : "accountStatus",
										"width" : "10%"
									}, {
										"data" : "buyersUserId",
										"width" : "25%"
									} ],
									"columnDefs" : [

											{
												"render" : function(data, type,
														row) {
													return dateTimeFormatter(data);
												},
												"targets" : 2
											},
											{
												"render" : function(data, type,
														row) {
													if (data == 0) {
														return '使用中';
													} else if (data == 1) {
														return '已冻结';
													}
												},
												"targets" : 7
											},
											{
												"render" : function(data, type,
														row) {
													var button = '冻结账号';
													if (row.accountStatus == 1) {
														button = '解冻账号';
													}
													var ret = '<button class="btn btn-warning userstatus" key="'+data+'" type="'+row.accountStatus+'">'
															+ button
															+ '</button>&nbsp;';
													ret += '<a class="btn btn-warning" href="'
															+ path
															+ '/user/buyerUserDetail?id='
															+ data
															+ '">查看详情</a>';
													return ret;
												},
												"targets" : 8
											} ]

								});
			}
			;

			//查询事件
			$('#search').click(function() {
				doSearch();
			});
			doSearch();
			bandclick();

			function bandclick() {
				$('body').on("click", '.userstatus', function() {
					_t = $(this);
					$.ajax({
						type : "post",
						url : path + "/user/editBuyerStatus",
						cache : false,
						data : {
							id : _t.attr('key'),
							accountStatus : _t.attr('type'),
							_t : new Date().getTime()
						},
						dataType : "json",
						success : function(data) {
							showmessage(data.msg);
							if (data.success) {
								doSearch(true);
							}
						}
					});
				});
			}
		});

		//导出
		$('#report').click(function() {
			$('#searchForm').attr("action", path + "/user/reportBuyers");
			$('#searchForm').submit();
			$('#searchForm').attr("action", "");
		});

		//显示消息
		function showmessage(msg, callback) {
			$('#message').ucMessage({
				msg : msg,
				callback : callback
			});
		}
	</script>
</body>
</html>